package com.alibaba.csp.sentinel.dashboard.rule.zookeeper;

import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity;
import com.alibaba.csp.sentinel.dashboard.rule.DynamicRuleProvider;
import com.alibaba.csp.sentinel.datasource.Converter;
import org.apache.curator.framework.CuratorFramework;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author ：qilong sun
 * @date ：Created in 2020/7/27 17:01
 * @description：
 * @modified By：
 * @version: V1.0$
 */

@Component("systemRuleZookeeperProvider")
public class SystemRuleZookeeperProvider implements DynamicRuleProvider<List<SystemRuleEntity>> {

    @Autowired
    private CuratorFramework zkClient;
    @Autowired
    private Converter<String, List<SystemRuleEntity>> converter;
    /**
     * 规则存储路径
     */
    @Value("${sentinel.rules.system.path}")
    String rulePath;

    @Override
    public List<SystemRuleEntity> getRules(String appName){
        return ZookeeperConfigUtilEx.getRules(rulePath,
                appName,
                zkClient,
                converter);
    }
}
